<?php
/**
 * IGUAN licence
 *
 * @copyright  Copyright (c) 2005-2010 ShopEx Technologies Inc_ (http://www_qinqinbaby_com)
 */

class esb_rpc_request_360buy_api  {

	private $client ;
	function __construct($params){	
		$this->client = new esb_rpc_request_360buy_sdk_JdClient();
		$this->client->appKey='D1014E996A6030BE0D8E968B369ACDDF';
		$this->client->appSecret='755ec5a96b224ff68f0c5b7933b4b89f';
		$this->client->serverUrl='';
		$this->client->accessToken='82e3192e-045f-4f8f-afba-b5fcccf5349d';
	}
	
	function store_trade_refund_add() {
		
		$request = new esb_rpc_request_360buy_sdk_request_order_OrderSearchRequest ();
		$m= $request->getApiMethod();
		 
		$request->setStartDate ( "2013-01-10 12:12:23" );
		$request ->setEndDate ( "2013-01-30 12:13:13" );
		$request ->setOrderState ( "WAIT_SELLER_STOCK_OUT" );
		$request ->setPage ( "1" );
		$request ->setPageSize ( "100" );
		$request ->setOptionalFields ( "vender_id,order_id,pay_type" );
		$response = $this->client ->execute ( $request );
		//var_dump($response);
		return $response;
	}
	
	function taobao_trade_fullinfo_get(){
		
		
	}
	
	/**
	 * 批量更新库存接口
	 * @param unknown_type $params
	 * @return Ambigous <multitype:, unknown>
	 */
	function store_items_quantity_list_update($params){

		$wareUpdateRequest = new WareUpdateRequest();
		wareUpdateRequest.setWareId("1100028130");
		wareUpdateRequest.setTitle("API商品测试-商品名称--修改商品");
		wareUpdateRequest.setLength("11");
		wareUpdateRequest.setWide("21");
		wareUpdateRequest.setHigh("31");
		wareUpdateRequest.setWeight("111");
		wareUpdateRequest.setMarketPrice("799");
		wareUpdateRequest.setJdPrice("680");
		wareUpdateRequest.setNotes("描述1修改商品23123	");
		wareUpdateRequest.setRate("331");
		wareUpdateRequest.setPackListing("包装清单--修改商品");
		wareUpdateRequest.setService("售后服务--修改商品");    wareUpdateRequest.setAttributes("3205:64734|3206:22107");
		wareUpdateRequest.setSkuProperties("1000000041:150029941^1000000046:150029944|1000000041:150029941^1000000046:150029943");
		wareUpdateRequest.setSkuPrices("600|700");
		wareUpdateRequest.setSkuStocks("100|900");
		$wareUpdateResponse= $this->client->execute(wareUpdateRequest);
		return $json;
	}
	/**
	 * 对买家已付款状态的交易进行发货操作 (同步) 商派已经禁用
	 */
	function store_trade_delivery_send($params){
		$apiResult = $this->apiRequest("store.trade.delivery.send", $params);


		return $apiResult;
	}

	 
	/**
	 * 更新单笔交易的发货状态 (同步)
	 * store.trade.shipping.status.update
	 * @param unknown_type $params
	 */
	function  store_trade_shipping_status_update($params){

		$apiResult = $this->apiRequest("store.trade.shipping.status.update", $params);
		
		$Result = json_decode($apiResult,true);
		
		//var_dump($Result);
		
		$rsp="fail";
		$res=$Result['res'];
		if($Result['rsp']=='succ')
		{$rsp="succ";
		//$res="成功";
		}
		 
		
		$json='{
	    	"rsp": "'.$rsp.'",
	   		 "msg_id":"3463421b2581604c74dcb9b74ffab2e4",
	   		 "res":"'.$res.'",
	    	"data":{
	        		    "tid":"'.$params['tid'].'",	           
	         		   "modified":"'.date("Y-m-d h:i:s",time()).'"
	   			 }
			}';
		//echo $json;
		return $json;
	}
	

	/**
	 * 修改交易发货单信息 (同步)
	 * store.trade.shipping.update
	 * @param unknown_type $params
	 */
	function  store_trade_shipping_update($params){
		$apiResult = $this->apiRequest("store.trade.shipping.update", $params);
		
		$Result = json_decode($apiResult,true);
		
		//var_dump($Result);
		
		$rsp="fail";
		$res=$Result['res'];
		if($Result['rsp']=='succ')
		{
			$rsp="succ";
			//$res="成功";
		}
		
		$json='{
		"rsp": "'.$rsp.'",
		"msg_id":"3463421b2581604c74dcb9b74ffab2e4",
		"res":"'.$res.'",
		"data":{
				"tid":"'.$params['tid'].'",
				"modified":"'.date("Y-m-d h:i:s",time()).'"
			}
		}';
		return $json;
	}
	/**
	 * 添加交易发货单 (同步)
	 *
	 * @param unknown_type $params
	 */
	function  store_trade_shipping_add($params){

		$apiResult = $this->apiRequest("store.trade.shipping.add", $params);
		
		$Result = json_decode($apiResult,true);
		
		$rsp="fail";
		$res=$Result['res'];
		if($Result['rsp']=='succ')
		{
			$rsp="succ";
			//$res="成功";
		}
		
		$json='{
		"rsp": "'.$rsp.'",
		"msg_id":"3463421b2581604c74dcb9b74ffab2e4",
		"res":"'.$res.'",
		"data":{
				"tid":"'.$params['tid'].'",
				"modified":"'.date("Y-m-d h:i:s",time()).'"
			}
		}';
		return $json;
	}
	
	/**
	 * 添加一笔交易的售后申请 (同步)
	 *
	 * @param unknown_type $params
	 */
	function  store_trade_aftersale_add($params){
		$apiResult = $this->apiRequest("store.trade.aftersale.add", $params);
		
		$Result = json_decode($apiResult,true);
		
		$data = $Result["data"];
		
		$rsp="fail";
		$res=$Result['res'];
		if($Result['rsp']=='succ')
		{
			$rsp="succ";
			//$res="成功";
		}
			
		$json='{
		"rsp": "'.$rsp.'",
		"msg_id":"3463421b2581604c74dcb9b74ffab224",
		"res":"'.$res.'",
		"data":{
		"trade":{
		"tid":"'.$params['tid'].'",
		"aftersale_id":"'.$data['aftersale_id'].'",
		"created":"'.date("Y-m-d h:i:s",time()).'"
		}
		}
		}';
		return $json;
		
	}
	/**
	 * 更新售后申请状态
	 * @param unknown_type $params
	 */
	function store_trade_aftersale_status_update($params){
		$apiResult = $this->apiRequest("store.trade.aftersale.status.update", $params);
		
		$Result = json_decode($apiResult,true);
		
		$data = $Result["data"];
		
		$rsp="fail";
		$res=$Result['res'];
		if($Result['rsp']=='succ')
		{
			$rsp="succ";
			//$res="成功";
		}
			
		$json='{
		"rsp": "'.$rsp.'",
		"msg_id":"3463421b2581604c74dcb9b74ffab224",
		"res":"'.$res.'",
		"data":{
		"trade":{
		"tid":"'.$params['tid'].'",
		"aftersale_id":"'.$data['aftersale_id'].'",
		"modified":"'.date("Y-m-d h:i:s",time()).'"
		}
		}
		}';
		return $json;
		
	}
	/**
	 * 添加交易退货单 (同步)
	 * store.trade.reship.add
	 * @param unknown_type $params
	 */
	function store_trade_reship_add($params){
	
		$json='{
			"rsp":"succ",
			"msg_id":"3463421b2581604c74dcb9b74ffab224",
			"data":{
			"trade":{
				"tid":"'.$params['tid'].'",
			 	"reship_id":"10101",
				"created":"'.date("Y-m-d h:i:s",time()).'"
				}
			}
		}';
		return $json;
	}
	
	
		/**
	 * 添加一笔交易的买家留言 (同步)
	 * store.trade.buyer_message.add
	 * @param unknown_type $params
	 */
	function store_trade_buyer_message_add($params){
		$res="成功";
		$json='{
			"rsp":"succ",
			"msg_id":"3463421b2581604c74dcb9b74ffab224",
			"res":"'.$res.'",
			"data":{
			"trade":{
				"tid":"'.$params['tid'].'",
				"created":"'.date("Y-m-d h:i:s",time()).'"
				}
			}
		}';
		return $json;
	}
			/**
	 * 添加一笔交易的买家留言 (同步)
	 * store.trade.memo.update
	 * @param unknown_type $params
	 */
	function store_trade_memo_update($params){
		$apiResult = $this->apiRequest("store.trade.memo.update", $params);
		
		$Result = json_decode($apiResult,true);
		
		$data = $Result["data"];
		
		$rsp="fail";
		$res=$Result['res'];
		if($Result['rsp']=='succ')
		{
			$rsp="succ";
			//$res="成功";
		}
			
		$json='{
			"rsp": "'.$rsp.'",
			"msg_id":"3463421b2581604c74dcb9b74ffab224",
			"res":"'.$res.'",
			"data":{
			"trade":{
				"tid":"'.$params['tid'].'",
				"created":"'.date("Y-m-d h:i:s",time()).'"
				}
			}
		}';
		return $json;
	}
	
	/**
	 * 
	 * @param unknown_type $params
	 * @return string
	 */
	function store_trade_payment_add($params){
		
		$apiResult = $this->apiRequest("store.trade.payment.add", $params);
		
		$Result = json_decode($apiResult,true);
		
		$data = $Result["data"];
		
		$rsp="fail";
		$res=$Result['res'];
		if($Result['rsp']=='succ')
		{
			$rsp="succ";
				//$res="成功";
		}
			
		
		$json='{
		"rsp": "'.$rsp.'",
		"msg_id":"3463421b2581604c74dcb9b74ffab2e4",
		"res":"'.$res.'",
		"data":{
		"tid":"'.$params['tid'].'"		
		}
		}';
		//echo $json;
		return $json;
		
	}
	
	 function  store_shop_payment_type_list_get(){
	 	
	 	$apiResult = $this->apiRequest("store.trade.payment.add", $params);
	 	
	 	$Result = json_decode($apiResult,true);
	 	
	 	$json='{
	 	"rsp": "succ",
	 	
	 	"data": ""
	 	}';
	 	//echo $json;
	 	return $json;
	 }
	/*
	'store.trade.update',
	'store.trade.shippingaddress.update',
	'store.trade.memo.add',
	'store.trade.memo.update',
	'store.trade.buyer_message.add',
	'store.trade.status.update',
	'store.trade.ship_status.update',
	'store.trade.shipping.add',
	'store.trade.shipping.update',
	'store.trade.shipping.status.update',
	'store.trade.reship.add',
	//'store.trade.reship.status.update',//TODO: 因发起的退货单本身是成功的，所以无需再同步退货单状态
	'store.trade.refund.add',
	'store.trade.payment.add',
	'store.items.quantity.list.update',
	'store.shop.payment_type.list.get',
	'store.trade.aftersale.status.update',
	'store.trade.aftersale.add',
	*/

	/**
	 * store.trade.status.update
	 * 更新单笔交易的状态 (同步)
	 * 交易状态，可选值： TRADE_ACTIVE:交易处理中, TRADE_CLOSED:交易作废即交易关闭, TRADE_FINISHED:交易成功
	*/
	function store_trade_status_update($params){
		$apiResult = $this->apiRequest("store.trade.status.update", $params);
		
		$Result = json_decode($apiResult,true);
		
		$data = $Result["data"];
		
		$rsp="fail";
		$res=$Result['res'];
		if($Result['rsp']=='succ')
		{
			$rsp="succ";
			//$res="成功";
		}
			
		
		$json='{
		"rsp": "'.$rsp.'",
		"msg_id":"3463421b2581604c74dcb9b74ffab2e4",
		"res":"'.$res.'",
		"data":{
		"tid":"'.$params['tid'].'"
		}
		}';
		//echo $json;
		return $json;
	}


}